<?php
namespace Home\Controller;

class WindowsClientSettingController extends ParentController
{
    protected function _initialize()
    {
        $this->validateUtil = new \Org\Util\Validate();
        $hotel = I('request.hotel');
        // 检查客栈是否已过期
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotel);
        if ($result == false) {
            returnJson(403, 408);
        }
        // 检查客栈状态
        $result = $hotelLogic->checkHotelStatus($hotel);
        if ($result == false) {
            returnJson(403, 401);
        }
        //检查权限
        //$adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');        
        //$adminAuthorityLogic->check($hotel);
    }

    public function getStatus()
    {
        $param = I('post.');
        
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        
        $hotelId = $param['hotel'];
        $HotelEntityModel = D('HotelEntity');
        $hotelInfo = $HotelEntityModel->getInfo($hotelId);
        returnJson(200, 200, array(
            'status' => ! empty($hotelInfo['clientswitch']),
            'checkRoom' => ! empty($hotelInfo['roomward']),
        ));
    }

    public function setStatus()
    {
        $param = I('post.');
        
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'status' => 'notnull,notempty,id',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        
        $hotelId = $param['hotel'];
        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $HotelEntityModel = D('HotelEntity');
        $result = $HotelEntityModel->saveInfo($hotelId, null, null, null, null, null, null, empty($param['status']) ? 0 : 1);
        returnJson(200, 200, $result);
    }
}
